/*
 * @lc app=leetcode.cn id=1260 lang=javascript
 *
 * [1260] 二维网格迁移
 */
// @lc code=start
/**
 * @param {number[][]} grid
 * @param {number} k
 * @return {number[][]}
 */
var shiftGrid = function (grid, k) {
  const tranferGrid = function (arr) {
    var res = [];
    for (var i = 0; i < arr[0].length; i++) {
      res[i] = [];
    }
    for (var i = 0; i < arr.length; i++) {
      for (var j = 0; j < arr[i].length; j++) {
        res[j][i] = arr[i][j];
      }
    }
    return res;
  }
  let arr = tranferGrid(grid);
  while (k--) {
    let col = arr[arr.length - 1];
    col = [col[col.length - 1], ...col.slice(0, col.length - 1)];
    arr = [col, ...arr.slice(0, arr.length - 1)];
  }
  return tranferGrid(arr);
};
// @lc code=end
